package com.ophiux.cs.infrastructure.repositories.user;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ophiux.cs.domain.consultBase.model.entity.Focus;
import com.ophiux.cs.domain.consultBase.model.valueobj.FocusValueObj;
import com.ophiux.cs.domain.consultBase.model.valueobj.GetFocusDoctorsValueObject;
import com.ophiux.cs.domain.consultBase.repositories.IFocusRepository;
import com.ophiux.cs.infrastructure.mapper.consultBase.FocusMapper;
import com.ophiux.utils.exception.OphiuxRepositoryException;

import lombok.extern.slf4j.Slf4j;

@Repository
@Slf4j
public class FocusRepository implements IFocusRepository{
	@Autowired
	FocusMapper focusMapper;
	
	@Override
	public void save(Focus obj) throws OphiuxRepositoryException{
		try {
			FocusValueObj param = new FocusValueObj();
			param.setUSER_ID(obj.getUSER_ID());
			param.setTARGET_ID(obj.getTARGET_ID());
			param.setTARGET_TYPE(obj.getTARGET_TYPE());
			
			Focus focus = focusMapper.getFocusInfo(param);
			
			if(focus==null) {//数据库没有,则执行新增操作
				focusMapper.insert(obj);
			}else {
				focusMapper.update(obj);
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("数据库执行异常,异常信息",e);
			throw new OphiuxRepositoryException("数据库执行异常,异常信息",e);
		}
		
	}


	@Override
	public List<GetFocusDoctorsValueObject> getFocusDoctorList(FocusValueObj obj) throws OphiuxRepositoryException {
		List<GetFocusDoctorsValueObject> list = new ArrayList<GetFocusDoctorsValueObject>();
		try {
			list = focusMapper.getFocusDoctorList(obj);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("数据库执行异常,异常信息",e);
			throw new OphiuxRepositoryException("数据库执行异常,异常信息",e);
		}
		return list;
	}
	
}
